package com.k.sshm.cloud.alibaba.seata.service.impl;

import com.k.sshm.cloud.alibaba.seata.dao.OrderDAO;
import com.k.sshm.cloud.alibaba.seata.model.Order;
import com.k.sshm.cloud.alibaba.seata.service.AccountService;
import com.k.sshm.cloud.alibaba.seata.service.OrderService;

public class OrderServiceImpl implements OrderService {

    private OrderDAO orderDAO;

    private AccountService accountService;

    @Override
    public Order create(String userId, String commodityCode, int orderCount) {

        int orderMoney = 0;

        accountService.debit(userId, orderMoney);

        Order order = new Order();
        order.userId(userId);
        order.commodityCode(commodityCode);
        order.count(orderCount);
        order.money(orderMoney);

        // INSERT INTO orders ...
        return orderDAO.insert(order);
    }
}